package com.cupk.controller;

import com.cupk.pojo.User;
import com.cupk.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 名称UserController
 * 描述User控制类
 *
 * @version 1.0
 * @author:zschun
 * @datatime:2022-06-23 17:20
 */
@RequestMapping("/user")
@Controller
public class UserController {
    @Autowired(required = false)
    private UserService userService;

    @GetMapping("findbyid")
    public String findUserById(Integer id, Model model){
        User user=userService.findUserById(id);
        System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%"+user);
        model.addAttribute("msg","User信息查询成功");
        return "public/success";
    }

    @GetMapping("findUwO")
    public String findUserWithOrder(Integer id, Model model){
        User user=userService.findUserWithOrders(id);
        System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%"+user);
        model.addAttribute("msg","User信息查询成功");
        return "public/success";
    }

    @GetMapping("/findall")
    public String findAllUsers(Model model){
        List<User> users=userService.findAllUsers();
        for (User u:users)
            System.out.println(u);
        model.addAttribute("msg","全部用户信息查询成功");
        return "public/success";
    }
}
